package com.briup.day05;

import java.util.Arrays;

/**
 * @author 谭梦寻
 * @version 1.1
 * 打印杨辉三角
 */
public class Test03 {
    //    实现杨辉三角
    public static void method01(int line) {
        int[][] arr = new int[line][];

        for (int i = 0; i < arr.length; i++) {
            arr[i] = new int[i + 1];
//        对二维数组中每个值进行赋值
            for (int j = 0; j < arr[i].length; j++) {
                if (j == 0 || j == arr[i].length - 1) {
                    arr[i][j] = 1;
                } else {
                    arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
//输出
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < (arr.length - i - 1); j++) {
                System.out.print(" ");
            }
//            控制输出二维数组中的值 记得值和值之间有空格隔开
            for (int k = 0; k < arr[i].length; k++) {
                try{
                    System.out.print(arr[i][k] + " ");
                }catch (IndexOutOfBoundsException e) {
                    System.out.println(e);
                }

            }
            System.out.println("");
        }

    }

    public static void main(String[] args) {
        method01(5);
    }
}
